/*
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 */
package net.sf.l2j.gameserver.model.entity.eventengine.events;

import net.sf.l2j.gameserver.ThreadPoolManager;
import net.sf.l2j.gameserver.model.Location;
import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
import net.sf.l2j.gameserver.model.entity.eventengine.AbstractEvent;
import net.sf.l2j.gameserver.model.entity.eventengine.EventPlayer;

/**
 * @author Anarchy
 *
 */
public class DeathMatch extends AbstractEvent
{
	@Override
	public void onTeleported()
	{
		for (EventPlayer p : _players)
		{
			p.getPlayer().setIsParalyzed(true);
			p.getPlayer().startAbnormalEffect(0x0400);
			p.saveTitle();
			p.getPlayer().setTitle("Kills: 0");
		}
	}
	
	@Override
	public void onStart()
	{
		for (EventPlayer p : _players)
		{
			p.getPlayer().setIsParalyzed(false);
			p.getPlayer().stopAbnormalEffect(0x0400);
		}
	}
	
	@Override
	public void onEnd()
	{
		int i = 0;
		EventPlayer winner = null;
		
		for (EventPlayer p : _players)
		{
			if (p.getEventPoints() > 0)
			{
				i = p.getEventPoints();
				winner = p;
			}
			
			p.restoreTitle();
			p.getPlayer().teleToLocation(new Location(p.loadXYZ()[0], p.loadXYZ()[1], p.loadXYZ()[2]), false);
		}
		
		winner.getPlayer().sendMessage("You won the event with "+i+" kills.");
		winner.getPlayer().addItem("Reward.", 3470, 1, winner.getPlayer(), true);
	}
	
	@Override
	public void onKill(L2PcInstance killer, L2PcInstance p)
	{
		EventPlayer ep = getEventPlayerObject(killer);
		ep.increaseEventPoints();
		killer.setTitle("Kills: "+ep.getEventPoints());
		ThreadPoolManager.getInstance().scheduleGeneral(new EventReviveTask(p, 0, 0, 0), 5000);
	}
	
	@Override
	public int getMinPlayers()
	{
		return 3;
	}
	
	@Override
	public Location getEventLocation()
	{
		return new Location(0, 0, 0);
	}
	
	@Override
	public boolean isTeamEvent()
	{
		return false;
	}
	
	@Override
	public String getName()
	{
		return "DeathMatch";
	}

	@Override
	public String getEventTimes()
	{
		return "12:00;13:00;15:00;18:50";
	}

	@Override
	public int[] getWaitTimes()
	{
		int[] times = { 120, 10, 10, 180 };
		return times;
	}
}